package fallowme.server;


import java.util.LinkedList;

/**
 * User to use in the Birdsong. The user had a nick name and a ListOfEstaASeguir and a listOfSeguidores
 * 
 * @author Pedro
 *
 */

public class User {

	LinkedList<String> listOfEstaASeguir;
	LinkedList<String> listOfSeguidores;


	String user;
	Boolean isConnected = false;

	/**
	 * Constructor, it construct a new User and create an empty listOfEstaASeguir and listOfSeguidores for the User
	 * @param user  The Nickname of the User
	 */
	public User(String user) {

		this.user = user;

		listOfEstaASeguir = new LinkedList<String>();
		listOfSeguidores = new LinkedList<String>();
	}

	/**
	 * Get the Nickname from the User
	 * @return the user name
	 */
	public String getUser(){

		return user;
	}

	/**
	 * Get the list of users that the user is following
	 * @return listOfEstaASeguir
	 */

	public LinkedList<String> getEstaASeguir() {
		return listOfEstaASeguir;
	}

	/**
	 * Add a new nickname to the user list of people he is following
	 * @param nick   nickname to had to add to the list
	 */
	public void addEstaASeguir(String nick){
		listOfEstaASeguir.add(nick);
	}

	/**
	 * Add a new nickname to the user list of people who follows him
	 * @param nick nickname to add to the list
	 */
	public void addSeguidor(String nick){
		listOfSeguidores.add(nick);
	}

	/**
	 * Removes a nickname from his list of nicknames the user is following
	 * @param nick nickname to remove
	 */
	public void removeEstaASeguir(String nick){

		listOfEstaASeguir.remove(nick);
	}


	/**
	 * Removes all nicknames from the list the use is following
	 */
	public void removeAllEstaASeguir(){
		listOfEstaASeguir.clear();
	}

	/**
	 * 
	 * @return <b>true</b> if a client with the nickname is currently connected, otherwise <b>false</b>.
	 */
	public Boolean isConnected (){

		return isConnected;
	}


	/**
	 * Set the user as Connected = true
	 */
	public void setConnected(){

		isConnected = true;
	}


	/**
	 * Set the user as Connected = false
	 */
	public void setDisconnect(){

		isConnected = false;
	}

	/**
	 * Return the user name as a String
	 */
	@Override
	public String toString() {
		return user;
	}

	/**
	 * Checks if the nickname is already in the list that the user is following
	 * @param payload  nickname of the user to check
	 * @return
	 */
	public boolean inTheListASeguir(String payload) {

		for(String l :listOfEstaASeguir){
			if(l.equals(payload))
				return true;
		}
		return false;
	}


	/**
	 * Checks if a user is following  a certain nickname.
	 * @return <b>true</b> if a client with the nickname is currently in the list, otherwise <b>false</b>.
	 */
	public boolean isListASeguirEmpty(){
		if (listOfEstaASeguir.isEmpty())
			return true;
		return false;
	}

	/**
	 * Checks if the list of followers is empty
	 * @return <b>true</b> if a user list is empty, otherwise <b>false</b>.
	 */
	public boolean isListSeguidoresEmpty() {
		if (listOfSeguidores.isEmpty())
			return true;
		return false;
	}


	/**
	 * Get the list of nicknames that follows the user
	 * @return listOfSeguidores
	 */
	public LinkedList<String> getSeguidores() {

		return listOfSeguidores;
	}

	/**
	 * Removes all nicknames form the list of followers
	 */
	public void removeAllSeguidores() {

		listOfSeguidores.clear();

	}

	/**
	 * Removes a nickname from the list of followers
	 * @param clientNickname   nickname to remove
	 */
	public void removeSeguidor(String clientNickname) {

		listOfSeguidores.remove(clientNickname);

	}

}